package redlib.backend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redlib.backend.annotation.BackendModule;
import redlib.backend.annotation.NeedNoPrivilege;
import redlib.backend.annotation.Privilege;
import redlib.backend.dto.ContactDTO;
import redlib.backend.dto.query.ContactQueryDTO;
import redlib.backend.model.Page;
import redlib.backend.service.ContactService;
import redlib.backend.vo.ShowPronvinceVO;
import redlib.backend.vo.ContactVO;

import java.util.List;

@RestController
@RequestMapping("/api/contact")
@BackendModule({"page:页面", "update:修改", "add:创建", "delete:删除"})
public class ContactController {
    @Autowired
    private ContactService contactService;

    @PostMapping("addContact")
    @Privilege({"add"})
    public Integer addContact(@RequestBody ContactDTO contactDTO){
        return contactService.insert(contactDTO);
    }

    @PostMapping("deleteContact")
    @Privilege({"delete"})
    public void deleteContact(@RequestBody List<Integer> ids) {
        contactService.deleteByCodes(ids);
    }

    @PostMapping("updateContact")
    @Privilege("update")
    public Integer updateContact(@RequestBody ContactDTO contactDTO) {
        return contactService.updateRecord(contactDTO);
    }
    @PostMapping("listContact")
    @Privilege("page")
    public Page<ContactVO> listContact(@RequestBody ContactQueryDTO queryDTO) {
        return contactService.listByPage(queryDTO);
    }
    @PostMapping("showProvince")
    @NeedNoPrivilege
    public List<ShowPronvinceVO> showProvince() {
        return contactService.showProvince();
    }
}
